<?php

    function read()
    {
        $fin = fopen( "post-word-tags.txt","r");
 //       $fin = fopen( "aaa.txt","r");

        if( $fin == NULL)
        {
            echo "file NOT OPEN\n";exit;
        }

        $arrTerms =  array();
 //       $pattern =  '/([\xEA-\xED][\x80-\xBF]{2}|[\!-\/]|[\[-\`]|[\{-\~])+/';
        $pattern =  '/([\xEA-\xED][\x80-\xBF]{2})+/';
        while( !feof( $fin ))
        {
            $line = trim( fgets( $fin ) );

            if( $line == "") continue;

            $arrWord = explode("\t", $line);


            preg_match_all($pattern, $arrWord [ 0 ], $match);
            $word = trim(  implode('', $match[0]));

            if( $word == "" || $word != $arrWord [ 0 ] )
            {
                unset( $line );
                unset( $match);
                unset( $arrWord);
                continue;
            }

            //$data =  $arrWord[0].":";
            $data =  '';

            if( count( $arrWord ) < 2) continue;
            for($i=1; $i< count( $arrWord );$i++)
            {
                $arrTmp = split("/", $arrWord[$i]);

                if( $arrTmp [1] >= 5)
                {
                    $data .= $arrTmp[0].":".$arrTmp[1];
                }
                else
                    continue;

                if( $i < count($arrWord ) -1 )
                    $data .= ":";
                unset( $arrTmp );
            }

            if($data == '') continue;

            $data = $arrWord[0].":".$data;
            if( array_key_exists( $arrWord[0], $arrTerms) == false)
            {
                $arrTerms[ $arrWord[0] ]= $data;
            }
 //          echo $data."<<\n";;
            unset($data);

            unset( $line );
            unset( $match);
            unset( $arrWord );
        }


        sort( $arrTerms );

        foreach( $arrTerms as $key => $value)
        {
            echo trim($value)."\n";
        }
        fclose( $fin );
    }

    read();
?>
